package stsj.meddroid.elements;

import stsj.meddroid.Resources;
import stsj.meddroid.screen.BattleScreen;

import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Rectangle;

public class Orb {
	public static final int HEALTH = 0;
	public static final int ENERGY = 1;
	public static final int ELIXIR = 2;
	
	public static final int EDIBLE = 0;
	public static final int EATEN = 1;	
	
	public static final int MUP = 0;
	public static final int MDOWN = 1;
	public static final int MLEFT = 2;
	public static final int MRIGHT = 3;
	public static final int AMMOUNT = 8;

	public int type;
	public int state;
	public int x;
	public int y;
	private Rectangle orbRectangle;
	private Rectangle centerOrbRectangle;
	private Sprite orbSprite;
	
	
	public Orb(int type,int a, int b) {
		this.type = type;
		this.x = a;
		this.y = b;
		this.orbRectangle = new Rectangle(x-100,y-100,200,200);
		if (type == HEALTH){this.orbSprite = new Sprite(Resources.buttonDll,64*6,64*5,64,64);}
		else if (type == ENERGY){this.orbSprite = new Sprite(Resources.buttonDll,64*7,64*5,64,64);}
		else if (type == ELIXIR){this.orbSprite = new Sprite(Resources.buttonDll,64*8,64*5,64,64);}
		this.orbSprite.setSize(48, 48);
		this.orbSprite.setPosition(x-24, y-24);
		this.state = EDIBLE;
		this.centerOrbRectangle = new Rectangle(x-24,y-24,48,48);
	}
	
	public void moveDown(int i){
		y = y - i; 
		if (state == EDIBLE){
			orbSprite.setPosition(x-24, y-24);
			orbRectangle.setY(y-100);
			centerOrbRectangle.setY(y-24);
		}
	}
	
	public void moveUp(int i){
		y = y + i;
		if (state == EDIBLE){
			orbSprite.setPosition(x-24, y-24);
			orbRectangle.setY(y-100);
			centerOrbRectangle.setY(y-24);
		}
	}
	
	public void moveLeft(int i){
		x = x - i;
		if (state == EDIBLE){
			orbSprite.setPosition(x-24, y-24);
			orbRectangle.setX(x-100);
			centerOrbRectangle.setX(x-24);
		}
	}
	
	public void moveRight(int i){
		x = x + i;
		if (state == EDIBLE){
			orbSprite.setPosition(x-24, y-24);
			orbRectangle.setX(x-100);
			centerOrbRectangle.setX(x-24);
		}
	}
	
	public void setType(int a) {
		type = a;
	}

	public int getType() {
		return type;
	}

	public void setX(int a) {
		this.x = a;
	}

	public int getX() {
		return x;
	}

	public void setY(int a) {
		this.y = a;
	}

	public int getY() {
		return y;
	}

	public int getState() {
		return state;
	}
	
	public Sprite getSprite() {
		return orbSprite;
	}

	public Rectangle getOuterRectangle() {
		return orbRectangle;
	}
	
	public Rectangle getCoreRectangle() {
		return centerOrbRectangle;
	}
	
	public void eaten(MedDroid medDroid) {
		if (type == HEALTH) {
			medDroid.healed(AMMOUNT);
		} else if (type == ENERGY) {
			medDroid.rechargeEnergy(AMMOUNT);
		} else if (type == ELIXIR) {
			medDroid.rechargeEnergy(13);
			medDroid.healed(13);
		}
		Resources.playSound(Resources.orbSound);
		state = EATEN;
		centerOrbRectangle.setX(1000);
		centerOrbRectangle.setY(1000);
		orbRectangle.setX(1000);
		orbRectangle.setY(1000);
		orbSprite.setPosition(1000, 1000);
	}
}
